﻿using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using WMSUIMVC.DTO.Finance;
using WMSUIMVC.DTO.Stocktaking;
using XuanKeZz.Application.HTTP;

namespace WMSUIMVC.Controllers
{
    /// <summary>
    /// 仓库——盘点管理
    /// </summary>
    public class StocktakingController : Controller
    {
        private readonly IConfiguration _configuration;

        public StocktakingController(IConfiguration configuration)
        {
            _configuration = configuration;
        }

        public IActionResult Stocking()
        {
            return View();
        }
        /// <summary>
        /// 显示仓库盘点
        /// </summary>
        /// <param name="Token"></param>
        /// <returns></returns>
        public async Task<IActionResult> GetInventory(SelectInventoryDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "ckd/api/Stocktaking/GetInventory?InventoryCode=" + dto.InventoryCode+"&Kdate="+dto.Kdate+"&InventoryState="+dto.InventoryState+"&office_id="+dto.office_id+"&PageIndex="+dto.PageIndex+"&PageSize="+dto.PageSize;
            string GetInventorys = await client.GetAsync(url);
            return Json(GetInventorys);
        }
        /// <summary>
        /// 添加盘点视图
        /// </summary>
        /// <returns></returns>
        public IActionResult ADDStocking()
        {
            return View();
        }
        /// <summary>
        /// 添加盘点方法
        /// </summary>
        /// <returns></returns>
        public async Task<IActionResult> ADDStockings(AddInventoryDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "ckx/api/Stocktaking/AddInventory";
            string list = JsonConvert.SerializeObject(dto);
            string AddInventorys = await client.PostAsync(url, list);
            return Json(AddInventorys);
        }
        /// <summary>
        /// 删除盘点方法
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task<IActionResult> DelFinanceReces(DelInventoryDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "ckx/api/Stocktaking/DelInventory";
            string list = JsonConvert.SerializeObject(dto);
            string DelInventory = await client.PostAsync(url, list);
            return Json(DelInventory);
        }
        /// <summary>
        /// 查看盘点详情
        /// </summary>
        /// <param name="Token"></param>
        /// <returns></returns>
        public async Task<IActionResult> FanInventory(FanInventoryDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "ckd/api/Stocktaking/GetFanInventory?id="+dto.id;
            string GetInventorys = await client.GetAsync(url);
            return Json(GetInventorys);
        }
        /// <summary>
        /// 添加上传视图
        /// </summary>
        /// <returns></returns>
        public IActionResult StockingUpload()
        {
            return View();
        }
        /// <summary>
        /// 显示添加产品列表
        /// </summary>
        /// <param name="Token"></param>
        /// <returns></returns>
        public async Task<IActionResult> SelectInventoryProduce(SelectInventoryProduce dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "ckd/api/Stocktaking/GetInventProudect";
            string list = JsonConvert.SerializeObject(dto);
            string GetInventorys = await client.PostAsync(url,list);
            return Json(GetInventorys);
        }
        /// <summary>
        /// 上传盘点方法
        /// </summary>
        /// <returns></returns>
        public async Task<IActionResult> UpdStockings(UpdInventoryDTO dto)
        {
            HttpClientWrapper client = new HttpClientWrapper(dto.Token);
            string url = _configuration["Url"] + "ckx/api/Stocktaking/UplInventory";
            string list = JsonConvert.SerializeObject(dto);
            string AddInventorys = await client.PostAsync(url, list);
            return Json(AddInventorys);
        }
        /// <summary>
        /// 修改盘点视图
        /// </summary>
        /// <returns></returns>
        public IActionResult UpdInvent()
        {
            return View();
        }



    }
}
